package proyectoia;

import java.util.List;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CombinedDomainXYPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;

/**
 * A demonstration application showing how to create a vertical combined chart.
 *
 */
public class CombinedXYPlotDemo1 extends ApplicationFrame {

    public CombinedXYPlotDemo1(String title, List<Double> totalList) {
        super(title);
        JFreeChart chart = createCombinedChart(totalList);
        ChartPanel panel = new ChartPanel(chart, true, true, true, false, true);
        panel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(panel);
    }

    private JFreeChart createCombinedChart(List<Double> totalList) {

        // create subplot 1...
//        XYDataset data1 = createDataset1();
//        XYItemRenderer renderer1 = new StandardXYItemRenderer();
//        NumberAxis rangeAxis1 = new NumberAxis("Range 1");
//        XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
//        subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
//        
//        XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0);
//        annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
//        annotation.setRotationAngle(Math.PI / 4.0);
//        subplot1.addAnnotation(annotation);

        // create subplot 2...
        XYDataset data2 = createDataset2(totalList);



        XYItemRenderer renderer2 = new StandardXYItemRenderer();
        NumberAxis rangeAxis2 = new NumberAxis("Range 2");
        rangeAxis2.setAutoRangeIncludesZero(false);
        XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
        subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

        // parent plot...
        CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
        plot.setGap(10.0);

        // add the subplots...
//        plot.add(subplot1, 1);
        plot.add(subplot2, 1);
        plot.setOrientation(PlotOrientation.VERTICAL);
        // return a new chart containing the overlaid plot...
        return new JFreeChart("CombinedDomainXYPlot Demo",
                JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    }

    private XYDataset createDataset1(List<Double> totalList) {

        XYSeries series1 = new XYSeries("Series 1");
        for (int i = 0; i < totalList.size(); i++) {
            series1.add(i, totalList.get(i));
        }
//        series1.add(10.0, 12353.3);
//        series1.add(20.0, 13734.4);
//        series1.add(30.0, 14525.3);
//        series1.add(40.0, 13984.3);
//        series1.add(50.0, 12999.4);
//        series1.add(60.0, 14274.3);
//        series1.add(70.0, 15943.5);
//        series1.add(80.0, 14845.3);
//        series1.add(90.0, 14645.4);
//        series1.add(100.0, 16234.6);
//        series1.add(110.0, 17232.3);
//        series1.add(120.0, 14232.2);
//        series1.add(130.0, 13102.2);
//        series1.add(140.0, 14230.2);
//        series1.add(150.0, 11235.2);
//        for (int i = 1; i < 100000; ++i)
//        {
//            series1.add(10*i+150, 17000-i*2);
//        }
//
//        XYSeries series2 = new XYSeries("Series 2");
//        series2.add(10.0, 15000.3);
//        series2.add(20.0, 11000.4);
//        series2.add(30.0, 17000.3);
//        series2.add(40.0, 15000.3);
//        series2.add(50.0, 14000.4);
//        series2.add(60.0, 12000.3);
//        series2.add(70.0, 11000.5);
//        series2.add(80.0, 12000.3);
//        series2.add(90.0, 13000.4);
//        series2.add(100.0, 12000.6);
//        series2.add(110.0, 13000.3);
//        series2.add(120.0, 17000.2);
//        series2.add(130.0, 18000.2);
//        series2.add(140.0, 16000.2);
//        series2.add(150.0, 17000.2);
//        for (int i = 1; i < 100000; ++i)
//        {
//            series2.add(10*i+150, 17000+i);
//        }

        XYSeriesCollection collection = new XYSeriesCollection();
        collection.addSeries(series1);
//        collection.addSeries(series2);

        return collection;

    }

    private XYDataset createDataset2(List<Double> totalList) {
        XYSeries series = new XYSeries("Series 1");
        for (int i = 0; i < totalList.size(); i++) {
            series.add(i, totalList.get(i));
        }
        return new XYSeriesCollection(series);
    }
//    public static void main(final String[] args) 
//    {
//        demo = new CombinedXYPlotDemo1("CombinedDomainXYPlot Demo");
//        demo.pack();
//        RefineryUtilities.centerFrameOnScreen(demo);
//        demo.setVisible(true);
//    }
}